<?php
namespace app\api\model;
use think\Model;
use  think\Db;
use app\api\model\Venueappoint;

class Myevaluation extends Model{
    protected $table = 'gx_evaluate';
    protected $createTime = 'evaluation_time';
    protected $updateTime = false;
    public function selectLists($user_id){
       $Vmodel=new Venueappoint();
       $res=Db::name('evaluate')->field('id,img',true)->where(array('user_id'=>$user_id))->select();
       if(!empty($res)&&count($res)>0){
         foreach ($res as $key=>$va){
             $res[$key]['venueInfo']=$this->getVenunInfo($va['place_id']);
            // dump($va['place_id']);
             $result=$Vmodel->AppointChongZhus($user_id,$va['place_id']);
             if($result['dan']){
                 $res[$key]['info']=$result['dan']['startime'].":00-".$result['dan']['endtime'].":00";
                 $res[$key]['nums']=$result['dan']['endtime']-$result['dan']['startime'];
             }
           if($result[0]){
               $le=count($result[0]);
               $res[$key]['info']=$result[0][0].":00-".$result[0][$le-1].":00";
               $res[$key]['nums']=$result[0][$le-1]-$result[0][0];
           }
           if($result[1]){
               $le=count($result[1]);
               $res[$key]['info']=$result[1][0].":00-".$result[1][$le-1].":00";
               $res[$key]['nums']=$result[1][$le-1]-$result[1][0];
           }
            
         }
         
         return $res;
       }
     
    }
    
    public function selectInfo($user_id){
       $res=Db::name('evaluate')->where('user_id',$user_id)->select();
       $data_new=[];
       if(!empty($res)){
           foreach ($res as  $key=>$va){
               $data_new[$key]['jiben']=$va;
               $data_new[$key]['veinfo']=$this->getVenunInfo($va['place_id']);
               $data_new[$key]['count']=array_to_fe($va['appoint_time']);
           }
       }
       return $data_new;
    }
    public function getVenunInfo($place_id){
     $res=Db::query("SELECT
	p.img,
	p.designation,
	p.address,
	c.`name`
FROM
	gx_place p,
	gx_city c
WHERE
	p.area = c.id
AND p.id = ?",array($place_id));
     if(!empty($res)){
         foreach ($res as $key=>$va){
             $res[$key]['address']=$va['name'].$va['address'];
             unset($res[$key]['name']);
         }
        
         return $res[0];
     }
     
    }
    /**
     * 我的评价
     * 添加
     */
    public function evate($data){
       $res=$this->allowField(true)->save($data);
       if($res){
           return $res;
       }else{
           return 0;
       }
    }
}